import React, { Component } from 'react'
import moment from 'moment';
export default class Timer extends Component {
    state = {
        dateTime:moment().format('YYYY-MM-DD HH:mm:ss')
    }
    componentDidMount(){
        this.timer = setInterval(()=>{
            console.log('timer');
            this.setState({
                dateTime:moment().format('YYYY-MM-DD HH:mm:ss')
            })
        },1000);
    }

    componentWillUnmount(){
        clearInterval(this.timer);
    }
    render() {
        let {dateTime} = this.state;
        return (
            <div>
                当前时间是：{dateTime}
            </div>
        )
    }
}
